package com.guxingke.typecho4j.widget.provider;

import java.util.List;

import com.guxingke.typecho4j.jfinal.model.Comment;
import com.guxingke.typecho4j.jfinal.model.Content;
import com.guxingke.typecho4j.util.PageBean;

/**
 * 抽象评论组件
 * 
 * @author guxingke
 * */
public abstract class CommentBaseWidget extends ProviderWidget {

	protected List<Comment> getRecentComments() {
		return Comment.dao.getRecentComments(constants.getPageSize());
	}

	protected List<Comment> getCommentsByCSlug(String slug,
			PageBean pageBean) {
		Long cid = Content.dao.getCidBySlug(slug);
		return Comment.dao.getCommentsByCid(cid, pageBean);
	}

	protected Long getCommentsNum() {
		return Comment.dao.getCommentsNum();
	}

	protected List<Comment> getCommentsByCid(Long cid, PageBean pageBean) {
		return Comment.dao.getCommentsByCid(cid, pageBean);
	}

	// 添加评论，更新内容表的commentsNum字段
	protected boolean addComment(Comment temp) {
		Content.dao.updateCommentsNum(temp.getLong("cid"));
		return temp.save();
	}

	protected List<Comment> getComments(PageBean pageBean) {
		return Comment.dao.getComments(pageBean);
	}

	protected void deleteComment(Long coid) {
		Comment.dao.deleteComment(coid);
	}
}
